package com.wsoft.form.controller;

import com.wsoft.form.query.table.TableInsertQuery;
import com.wsoft.form.query.table.TableListQuery;
import com.wsoft.form.query.table.TableUpdateQuery;
import com.wsoft.form.service.IWfFormTableService;
import com.wsoft.form.vo.TableVO;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 自定义表单-数据表 前端控制器
 * </p>
 *
 * @author Z001
 * @since 2024年08月29日 09:11:06
 */
@RestController
@Tag(name = "数据表")
@RequestMapping("/wf/table")
public class WfFormTableController {

    @Resource
    private IWfFormTableService tableService;


    @Operation(summary = "新增表", description = "新增表")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid TableInsertQuery req) {
        return ResponseResult.success(tableService.insertTable(req));
    }

    @Operation(summary = "修改表", description = "修改表")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid TableUpdateQuery req) {
        return ResponseResult.success(tableService.updateTable(req));
    }

    @Operation(summary = "获取表信息", description = "获取表信息")
    @GetMapping("/get")
    public ResponseResult get(@RequestParam("id") Long id) {
        return ResponseResult.success(tableService.getTableInfo(id));
    }

    @Operation(summary = "获取表结构", description = "删除获取表结构表字段")
    @GetMapping("/getColumnList")
    public ResponseResult getColumnList(@RequestParam("id") Long id) {
        return ResponseResult.success(tableService.getColumnList(id));
    }

    @Operation(summary = "列表页面", description = "列表页面")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody TableListQuery query) {
        List<TableVO> list = tableService.listTable(query);
        return ResponseResult.success(list);
    }

    @Operation(summary = "删除表", description = "删除表")
    @GetMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id) {
        boolean b = tableService.deleteTable(id);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

}
